import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class LoginFrame extends JFrame {
    private JTextField usernameField;  // 用户名输入框
    private JPasswordField passwordField;  // 密码输入框

    // 构造方法，设置界面基本属性
    public LoginFrame() {
        setLocationRelativeTo(null);  // 将界面居中显示
        setTitle("登录");  // 设置界面标题
        setSize(400, 300);  // 设置界面大小
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  // 设置关闭操作，结束当前窗口

        // 创建面板
        JPanel panel = new JPanel();
        add(panel);  // 将面板添加到界面

        // 使用 GridBagLayout 布局管理器
        panel.setLayout(new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.insets = new Insets(5, 5, 5, 5);  // 设置组件间隔
        gbc.anchor = GridBagConstraints.CENTER;  // 设置组件对齐方式为居中

        // 创建并添加管理员登录按钮
        JButton adminLoginButton = new JButton("管理员登录");
        gbc.gridx = 0;
        gbc.gridy = 0;
        panel.add(adminLoginButton, gbc);

        // 创建并添加客户登录按钮
        JButton customerLoginButton = new JButton("客户登录");
        gbc.gridx = 0;
        gbc.gridy = 1;
        panel.add(customerLoginButton, gbc);

        // 创建并添加注册按钮
        JButton registerButton = new JButton("客户注册");
        gbc.gridx = 0;
        gbc.gridy = 2;
        panel.add(registerButton, gbc);

        JButton logoutButton =new JButton("退出登录");
        gbc.gridx = 0;
        gbc.gridy = 3;
        panel.add(logoutButton, gbc);


        // 按钮事件监听器
        logoutButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
            }
        });


        adminLoginButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
                // 打开管理员登录界面
                AdminLoginFrame adminLoginFrame = new AdminLoginFrame();
                adminLoginFrame.setVisible(true);
            }
        });

        customerLoginButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
                // 打开客户登录界面
                CustomerLoginFrame customerLoginFrame = new CustomerLoginFrame();
                customerLoginFrame.setVisible(true);
            }
        });

        registerButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
                // 打开注册界面
                RegistrationFrame registrationFrame = new RegistrationFrame();
                registrationFrame.setVisible(true);
            }
        });
    }

    // 主方法，启动登录界面
    public static void main(String[] args) {
        LoginFrame loginFrame = new LoginFrame();
        loginFrame.setVisible(true);
    }
}
